﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using Csla.Serialization;
using System.Security.Principal;

namespace Authentication
{
    [Serializable]
    public class CustomPrincipal : ReadOnlyBase<CustomPrincipal>, IPrincipal
    {
        #region Business Methods
        private static PropertyInfo<CustomIdentity> CustomIdentityProperty = RegisterProperty<CustomIdentity>(p => p.CustomIdentity);
        public CustomIdentity CustomIdentity
        {
            get { return ReadProperty(CustomIdentityProperty); }
            private set { LoadProperty(CustomIdentityProperty, value); }
        }
        #endregion

        #region IPrincipal Members
        public IIdentity Identity
        {
            get { return ReadProperty(CustomIdentityProperty); }
        }

        public bool IsInRole(string role)
        {
            return CustomIdentity.IsInRole(role);
        }
        #endregion

        #region Constructor
        public CustomPrincipal()
        { /* require by MobileFormatter */ }

        public CustomPrincipal(CustomIdentity identity)
        {
            this.CustomIdentity = identity;
        }
        #endregion
    }
}
